{% load djblets_utils i18n reviewtags %}

{% if issues.total > 0 %}
<div class="content" id="issue-summary">
 <a name="issue-summary"></a>
 <h3>{% trans "Issues" %}</h3>
 <div class="header">
  <div class="counters">
   <span class="counter total">
    <label>{% trans "Total" %}:</label>
    <span id="total-counter">{{issues.total}}</span>
   </span>
   <span class="counter">
    <label>{% trans "Open" %}:</label>
    <span id="open-counter">{{issues.open}}</span>
   </span>
   <span class="counter">
    <label>{% trans "Resolved" %}:</label>
    <span id="resolved-counter">{{issues.resolved}}</span>
   </span>
   <span class="counter">
    <label>{% trans "Dropped" %}:</label>
    <span id="dropped-counter">{{issues.dropped}}</span>
   </span>
  </div>
  <div class="filters">
   <div class="filter-wrapper">
    <span><label for="issue-state-filter">{% trans "Status:" %}</label></span>
    <select class="filter" id="issue-state-filter">
     <option value="open">{% trans "Open" %}</option>
     <option value="dropped">{% trans "Dropped" %}</option>
     <option value="resolved">{% trans "Resolved" %}</option>
     <option value="all">{% trans "All" %}</option>
    </select>
   </div>
   <div class="filter-wrapper">
    <span><label for="issue-reviewer-filter">{% trans "From:" %}</label></span>
    <select class="filter" id="issue-reviewer-filter">
     <option value="all">{% trans "All" %}</option>
    </select>
   </div>
  </div>
 </div>
 <div class="issue-table-wrapper">
  <table id="issue-summary-table">
   <thead>
    <tr>
     <th class="description-header">{% trans "Description" %}</th>
     <th class="from-header">{% trans "From" %}</th>
     <th class="last-updated-header">{% trans "Last Updated" %}</th>
     <th class="status-header">{% trans "Status" %}</th>
    </tr>
   </thead>
   <tbody>
{% for entry in entries %}
{%  if entry.review %}
{%   for comment_type, comments in entry.comments.items %}
{%    for comment in comments %}
{%     if comment.issue_opened %}
    <tr id="summary-table-entry-{{comment.id}}" reviewer="{{entry.review.user|user_displayname}}" class="issue {{comment.issue_status|pretty_print_issue_status}}{% if comment.issue_status != 'O' %} hidden{% endif %}">
     <td class="summary-table-description"><a class="summary-anchor {% rich_text_classname comment.rich_text %}" comment-type="{{comment.comment_type}}" issue-id="{{comment.id}}" href="#{{comment.anchor_prefix}}{{comment.id}}">{{comment.text|render_markdown:comment.rich_text|striptags|truncatewords:20}}</a></td>
     <td class="reviewer"><a href="{% url 'user' entry.review.user %}" class="user">{{entry.review.user|user_displayname}}</a></td>
     <td class="last-updated" timestamp={{comment.timestamp|date:"U"}}>{{comment.timestamp}}</td>
     <td class="status">{{comment.issue_status|pretty_print_issue_status|capfirst}}</td>
    </tr>
{%     endif %}
{%    endfor %}
{%   endfor %}
{%  endif %}
{% endfor %}
   </tbody>
  </table>
 </div>
</div>
{% endif %}
